<!DOCTYPE html>
<html lang="en" class="no-js">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <title>学生截屏展示页面</title>
        <link rel="stylesheet" type="text/css" href="static/css/demo.css" />
        <link rel="stylesheet" type="text/css" href="static/css/component.css" />
        <script src="static/js/modernizr.custom.js"></script>
    </head>
    <body>
        <?php
        $cid = isset($_REQUEST['cid']) ? $_REQUEST['cid'] : '';
        //$node_grade_id  = isset($_REQUEST['node_grade_id']) ? $_REQUEST['node_grade_id']:'';
        $sn_group_id = isset($_REQUEST['sn_group_id']) ? $_REQUEST['sn_group_id'] : '';
        $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
        $thumb = $large = $files = $page_data = array();
        //error_reporting(E_ERROR | E_WARNING | E_PARSE);
        //@error_reporting(0);
        @set_time_limit(0);
        @set_magic_quotes_runtime(0);
        @ini_set('memory_limit', '512M');
        $whiteboard_config_array = array();
        if ($cid && $sn_group_id) {
            $isp = isset($_REQUEST['isp']) && !empty($_REQUEST['isp']) ? $_REQUEST['isp']:'';//运营商编号 1 电信 2 移动 3 联通
            if(empty($isp)){
                $isp = 1;
            }
            $whiteboard_config_array = parse_ini_file(SITE_ROOT."config/room/config_whiteboard_".$isp.".ini", false);
            require dirname(dirname(dirname(__FILE__))) . '/source/class/memory/memory_driver_redis_multi.php';
            $config_redis = array();
            $config_redis['master'] = array(
                array(
                    'host' => $whiteboard_config_array['MEMORY_REDIS_MASTER_SERVER'],
                    'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
                    'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
                    'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
                    'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
                    'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
                )
            );
            $config_redis['slave'] = array(
                array(
                    'host' => $whiteboard_config_array['MEMORY_REDIS_SLAVE_SERVER'],
                    'port' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PORT'],
                    'auth' => $whiteboard_config_array['MEMORY_REDIS_MASTER_AUTH'],
                    'db' => $whiteboard_config_array['MEMORY_REDIS_MASTER_DB'],
                    'pconnect' => $whiteboard_config_array['MEMORY_REDIS_MASTER_PCONNECT'],
                    'timeout' => $whiteboard_config_array['MEMORY_REDIS_MASTER_TIMEOUT']
                )
            );
            //DEBUG 初始化redis
            $redis = RedisClient::getInstance($config_redis);
            /*
             * 获取学生用户名
             */

            function get_user_realname($cid, $uid) {
                global $redis;
                $user_info = '';
                $user_info_array = array();
                $user_info = $redis->get($cid . '_' . $uid . '_user_info');
                $user_info_array = explode('#', $user_info);
                if (empty($user_info_array[3])) {
                    $user_info_array[3] = '学生' . $uid;
                }
                return $user_info_array[3];
            }

            @file_put_contents('./logs/upload_file/file_' . $cid . '.log', '');
            for ($i = 2; $i <= $whiteboard_config_array['SERVER_COUNT']; $i++) {
                $tmp = @file_get_contents('http://' . $whiteboard_config_array['SERVER_' . $i] . '/data/attachment/om_html5/' . $cid . '/file_' . $whiteboard_config_array['SERVER_' . $i] . '.log');
                if (strpos($tmp, ".jpg") || strpos($tmp, ".JPG")) {
                    @file_put_contents('./logs/upload_file/file_' . $cid . '.log', $tmp, FILE_APPEND);
                }
            }
            //DEBUG 取出数据前20个图片
            if (file_exists('./logs/upload_file/file_' . $cid . '.log')) {
                $files = file('./logs/upload_file/file_' . $cid . '.log');
                $per_page = 20; //DEBUG 每页20个
                $start = $per_page * ($page - 1);
                if (!empty($files)) {
                    $page_total = ceil(count($files) / $per_page);
                    for ($j = 0; $j < $per_page; $j++) {
                        $get_file_key = $start + $j;
                        $get_file = $files[$get_file_key];
                        $get_file_array = explode('_', $get_file);
                        if (!empty($get_file_array[2])) {
                            if (file_exists('../../data/attachment/om_html5/' . $cid . '/' . $get_file_array[2])) {
                                $page_data[$j]['path'] = '../../data/attachment/om_html5/' . $cid . '/' . $get_file_array[2];
                            } else {
                                $page_data[$j]['path'] = './openapi/om_html5/static/img/none.jpg';
                            }
                            $page_data[$j]['file_name'] = $get_file_array[2];
                            $page_data[$j]['realname'] = get_user_realname($cid, $get_file_array[1]);
                            $page_data[$j]['create_datetime'] = $get_file_array[3];
                        }
                    }
                    $thumb = $large = $page_data;
                }
            }
        }
        ?>
        <div class="container">
            <header class="clearfix">
                <h1>学生截屏展示页面</h1>
                <nav>
                    <?php if (1 < $page) {
                        ?>
                        <a href="./upload_file_gallery.php?cid=<?php echo $cid; ?>&node_grade_id=<?php echo $sn_group_id; ?>&page=<?php echo ($page - 1); ?>" class="bp-icon bp-icon-prev" data-info="前一页"><span>返回前一页</span></a>
                        <?php
                    }
                    if (($page + 1) < $page_total) {
                        ?>
                        <a href="./upload_file_gallery.php?cid=<?php echo $cid; ?>&node_grade_id=<?php echo $sn_group_id; ?>&page=<?php echo ($page + 1); ?>" class="bp-icon bp-icon-next" data-info="下一页"><span>返回前一页</span></a>
                        <?php
                    }
                    ?>
                </nav>
            </header>
            <div id="grid-gallery" class="grid-gallery">
                <section class="grid-wrap">
                    <ul class="grid">
                        <li class="grid-sizer"></li>
                        <?php
                        foreach ($thumb as $key => $value) {
                            ?>
                            <li>
                                <figure>
                                    <img src="<?php echo $value['path']; ?>" alt="<?php echo $value['file_name']; ?>"/>
                                    <figcaption><h3><?php echo $value['realname']; ?></h3><p><?php echo $value['create_datetime']; ?></p></figcaption>
                                </figure>
                            </li>
                            <?php
                        }
                        ?>
                    </ul>
                </section><!-- // grid-wrap -->
                <section class="slideshow">
                    <ul>
                        <?php
                        foreach ($large as $key => $value) {
                            ?>
                            <li>
                                <figure>
                                    <figcaption>
                                        <h3><?php echo $value['realname']; ?></h3>
                                        <p><?php echo $value['create_datetime']; ?></p>
                                    </figcaption>
                                    <img src="<?php echo $value['path']; ?>" alt="<?php echo $value['file_name']; ?>"/>
                                </figure>
                            </li>
                            <?php
                        }
                        ?>
                    </ul>
                    <nav>
                        <span class="icon nav-prev"></span>
                        <span class="icon nav-next"></span>
                        <span class="icon nav-close"></span>
                    </nav>
                    <div class="info-keys icon"></div>
                </section><!-- // slideshow -->
            </div><!-- // grid-gallery -->
        </div>
        <script src="static/js/imagesloaded.pkgd.min.js"></script>
        <script src="static/js/masonry.pkgd.min.js"></script>
        <script src="static/js/classie.js"></script>
        <script src="static/js/cbpGridGallery.js"></script>
        <script>
            new CBPGridGallery(document.getElementById('grid-gallery'));
        </script>
    </body>
</html>
<?php $redis->close(); ?>